﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Adaptive_Clustering
{
    public class ScanWindow
    {
        public ScanWindow()
        {
        }

        public int scanWindow(Byte[,] ImageClusterIndexArray, Byte[,] ImageArray, int LeftBorder, int RightBorder, int TopBorder, int ButtomBorder, Byte k)
        {
            // scaning window and return the avg of the center. returns -1 if amount of pixels is below the threshold (window width)
            int x, y;
            UInt64 sum = 0, counter = 0;
            for (x = LeftBorder; x < RightBorder; x++)
                for (y = TopBorder; y < ButtomBorder; y++)
                    if (!(ImageClusterIndexArray[x, y] == k)) //for every pixel s belongs to region k
                    { }//reduce miss panelty for 'if' statement
                    else
                    {
                        counter++;
                        sum += ImageArray[x, y];
                    }
            if (counter > ((UInt64)RightBorder - (UInt64)LeftBorder)) //if above threshold
                return (int)(sum / counter); //avg
            else //if below threshold signify that the intensity is undefined
                return -1;
        }
    }
}
